<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>事件 mouseenter 和 mouseleave</title>
		<style>
			.box {
				width: 200px;
				height: 200px;
				background-color: pink;
				margin: 100px auto;
			}

			.child {
				width: 100px;
				height: 100px;
				background-color: skyblue;
				margin: 50px 50px 50px 50px;
			}
		</style>
	</head>
	<body>
		<div class="box">
			父
			<div class="child">子</div>
		</div>

		<script>
			// mouseenter 和 mouseleave 特点：1、移入后台元素上不会触发；2、事件不会冒泡。

			const box = document.querySelector('.box')
			const child = document.querySelector('.child')

			// mouseenter 鼠标移入时触发
			box.addEventListener('mouseover', function (e) {
				console.log('mouseover 鼠标移入box')
			})

			// mouseleave 鼠标移出时触发
			box.addEventListener('mouseout', function (e) {
				console.log('mouseout 鼠标移出box')
			})

			// mouseenter 鼠标移入时触发
			// child.addEventListener('mouseenter', function (e) {
			// 	console.log('mouseenter 鼠标移入child')
			// })

			// mouseleave 鼠标移出时触发
			// child.addEventListener('mouseleave', function (e) {
			// 	console.log('mouseleave 鼠标移出child')
			// })
		</script>
	</body>
</html>
